﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Comercio.Models.DBM;

namespace Comercio.Controllers
{
    public class stockhistoricoController : Controller
    {
        private ECommerceEntities1 db = new ECommerceEntities1();

        //
        // GET: /stockhistorico/

        public ActionResult Index()
        {
            var tb_stock_historico = db.tb_stock_historico.Include(t => t.tb_producto).Include(t => t.tb_proveedor);
            return View(tb_stock_historico.ToList());
        }

        //
        // GET: /stockhistorico/Details/5

        public ActionResult Details(int id = 0)
        {
            tb_stock_historico tb_stock_historico = db.tb_stock_historico.Find(id);
            if (tb_stock_historico == null)
            {
                return HttpNotFound();
            }
            return View(tb_stock_historico);
        }

        //
        // GET: /stockhistorico/Create

        public ActionResult Create()
        {
            ViewBag.id_producto = new SelectList(db.tb_producto, "id_producto", "descripcion");
            ViewBag.rut_proveedor = new SelectList(db.tb_proveedor, "rut_proveedor", "razon_social");
            return View();
        }

        //
        // POST: /stockhistorico/Create

        [HttpPost]
        public ActionResult Create(tb_stock_historico tb_stock_historico)
        {
            if (ModelState.IsValid)
            {
                db.tb_stock_historico.Add(tb_stock_historico);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.id_producto = new SelectList(db.tb_producto, "id_producto", "descripcion", tb_stock_historico.id_producto);
            ViewBag.rut_proveedor = new SelectList(db.tb_proveedor, "rut_proveedor", "razon_social", tb_stock_historico.rut_proveedor);
            return View(tb_stock_historico);
        }

        //
        // GET: /stockhistorico/Edit/5

        public ActionResult Edit(int id = 0)
        {
            tb_stock_historico tb_stock_historico = db.tb_stock_historico.Find(id);
            if (tb_stock_historico == null)
            {
                return HttpNotFound();
            }
            ViewBag.id_producto = new SelectList(db.tb_producto, "id_producto", "descripcion", tb_stock_historico.id_producto);
            ViewBag.rut_proveedor = new SelectList(db.tb_proveedor, "rut_proveedor", "razon_social", tb_stock_historico.rut_proveedor);
            return View(tb_stock_historico);
        }

        //
        // POST: /stockhistorico/Edit/5

        [HttpPost]
        public ActionResult Edit(tb_stock_historico tb_stock_historico)
        {
            if (ModelState.IsValid)
            {
                db.Entry(tb_stock_historico).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.id_producto = new SelectList(db.tb_producto, "id_producto", "descripcion", tb_stock_historico.id_producto);
            ViewBag.rut_proveedor = new SelectList(db.tb_proveedor, "rut_proveedor", "razon_social", tb_stock_historico.rut_proveedor);
            return View(tb_stock_historico);
        }

        //
        // GET: /stockhistorico/Delete/5

        public ActionResult Delete(int id = 0)
        {
            tb_stock_historico tb_stock_historico = db.tb_stock_historico.Find(id);
            if (tb_stock_historico == null)
            {
                return HttpNotFound();
            }
            return View(tb_stock_historico);
        }

        //
        // POST: /stockhistorico/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            tb_stock_historico tb_stock_historico = db.tb_stock_historico.Find(id);
            db.tb_stock_historico.Remove(tb_stock_historico);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}